A continuously animated application swaps buffers frequently enough that the operation should be optimized. As explained earlier, SGI implements a buffer swap by toggling the display mode table entry for the unshared DID assigned to the window during vertical retrace.
If the glXSwapBuffers command is called on the currently bound window, the buffer swap is considered to be in the OpenGL command stream. This allows a direct renderer to provide a buffer swap without contacting the X server. The graphics driver provides a ``buffer swap'' ioctl which can be issued by direct renderers. The result is to schedule a buffer swap at the next vertical retrace for the thread's currently bound window. If the glXSwapBuffers command is not for the currently bound window, the OpenGL library generates a GLX protocol request to swap the buffers and lets the X server perform the buffer swap.
The ioctl returns immediately. This is good because waiting for the vertical retrace could cause a delay equal to the vertical retrace interval (typically at the rate of 60 times per second). But further drawing to the window must be held off until the buffer swap completes. To do this, the graphics driver invalidates the ``allow rendering'' resource and invalidates the virtual memory mapping to the graphics pipe. Any further access to the pipe by the rendering node will stall the process until the buffer swap completes. When the buffer swap completes, the ``allow rendering'' resource will be revalidated so rendering can continue.
Because which buffer is front and which is back is window state shared by all OpenGL direct renderers bound to the window, the kernel will also update the absolute sense of what buffer is front and back for any other rendering nodes bound to the window being swapped. The graphics hardware provides a means to switch what buffer is the front and back buffer without the knowledge of the direct renderer.
The advantage of not immediately stalling the process until the buffer swap completes is that most animation applications have a certain amount of computation to do before the next image (typically called a frame) can be rendered. By not immediately stalling the process, this computation can be overlapped with waiting for the buffer to swap.